# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Sherlock Holo <sherlockya(at)gmail.com>
# Contributor: Ariel AxionL <i [at] axionl [dot] me>

pkgname=dns-over-https
pkgver=2.3.3
pkgrel=1
pkgdesc="Client and server software to query DNS over HTTPS, using Google DNS-over-HTTPS protocol"
url="https://github.com/m13253/dns-over-https"
arch=('loong64' 'x86_64')
license=('MIT')
backup=('etc/dns-over-https/doh-client.conf'
        'etc/dns-over-https/doh-server.conf')
provides=('dns-over-https-client' 'dns-over-https-server')
makedepends=('go' 'git')
options=('!lto')
source=("$pkgname-$pkgver.tar.gz::https://github.com/m13253/dns-over-https/archive/v$pkgver.tar.gz")
sha256sums=('cd95bf9594bacc2c97463bf745b072bd88523f0cd67e951002a3444f15dc59c4')

prepare(){
  cd "$pkgname-$pkgver"
  sed -i 's/\/local//g' systemd/doh-{client,server}.service
}

build() {
  cd "$pkgname-$pkgver"
  export GOFLAGS="-trimpath"
  export CGO_LDFLAGS="${LDFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  go build -v -o client ./doh-client
  go build -v -o server ./doh-server
}

check(){
  cd "$pkgname-$pkgver"
  go test -v ./...
}

package() {
  cd $pkgname-$pkgver
  install -Dm755 client "$pkgdir"/usr/bin/doh-client
  install -Dm644 doh-client/doh-client.conf -t "$pkgdir"/etc/dns-over-https/
  install -Dm644 systemd/doh-client.service -t "$pkgdir"/usr/lib/systemd/system/
  install -Dm755 NetworkManager/dispatcher.d/doh-client -t "$pkgdir"/etc/NetworkManager/dispatcher.d/

  install -Dm755 server "$pkgdir"/usr/bin/doh-server
  install -Dm644 doh-server/doh-server.conf -t "$pkgdir"/etc/dns-over-https/
  install -Dm644 systemd/doh-server.service -t "$pkgdir"/usr/lib/systemd/system/
  install -Dm755 NetworkManager/dispatcher.d/doh-server -t "$pkgdir"/etc/NetworkManager/dispatcher.d/

  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
